import { inject, observer} from 'mobx-react';
import { WeaSearchGroup,WeaFormItem,WeaLocaleProvider } from 'ecCom';
import { WeaSwitch } from 'comsMobx';
import { Button } from 'antd';
const getLabel = WeaLocaleProvider.getLabel;
@inject('wfCenterStore')
@observer
class Condition extends React.Component{

   
    switchChange = (v) => {
      const { settingForm } = this.props.wfCenterStore;
      if(Object.keys(v)[0] == "fromType" ){
          settingForm.updateFields({
            'workflowids': {value: []},
            'workflowtypes': {value: []}
          })
        } 
    }
    render(){
        const { settingForm, settingFormCondition, centerSetState} = this.props.wfCenterStore;
        let formParams = settingForm.getFormParams();
        let arr = [];
       
        let { orderTitles='',eFieldTitles='', showTypeTitles='' } = this.props.titleObj;
        settingForm.isFormInit && settingFormCondition.map ( (v,index) => {
          let items = [];
          v.items.map ((item) => {
            let pushItem = () => {
                items.push({
                  com: (
                    <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@9kiiae@${item.domkey[0]}`}
                      label={item.label}
                      labelCol={{span: `${item.labelcol}`}}
                      wrapperCol={{span: `${item.fieldcol}`}}
                      error={settingForm.getError(item)}
                      tipPosition="bottom"
                      >
                      <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@ie3a2w@${item.domkey[0]}`} fieldConfig={item} form={settingForm} onChange={this.switchChange}
                      />
                    </WeaFormItem>
                  )
                })
            }
            if(item.domkey[0] == 'workflowids' && (formParams.fromType == '1' ||formParams.fromType == '2')) {
              pushItem();
            }
            if(item.domkey[0] == 'workflowtypes' && (formParams.fromType == '3' || formParams.fromType == '4')) {
              pushItem();
            }
            if(item.domkey[0] == 'fromType' || item.domkey[0] == 'perpagewfcenter') {
                pushItem();
            }
            if(item.domkey[0] == 'showcol' ||  item.domkey[0] == 'ordercol' || item.domkey[0] == 'showtypeids' ){
              items.push({
                com: (
                  <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@8qcgad@${item.domkey[0]}`}
                    label={item.label}
                    labelCol={{span: `${item.labelcol}`}}
                    wrapperCol={{span: `${item.fieldcol}`}}
                  >
                    {
                      item.domkey[0] == 'showcol' && <div className='setting-warp'>
                      <em className="icon-coms-Flow-setting cursor-pointer" onClick={() => {centerSetState({eFieldNewVisible:true})}}></em>
                      <div className='checked-words-div'><span>{ eFieldTitles}</span></div>
                      </div>
                    } 
                    {
                      item.domkey[0] == 'ordercol' && <div className='setting-warp'>
                      <em className="icon-coms-Flow-setting cursor-pointer" onClick={() => {centerSetState({orderColVisible:true})}}></em>
                      <div className='checked-words-div'><span>{orderTitles}</span></div>  
                      </div>
                    }
                    {
                      item.domkey[0] == 'showtypeids' && <div className='setting-warp'>
                      <em className="icon-coms-Flow-setting cursor-pointer"onClick={() => {centerSetState({showTypeNewVisible:true})}}></em> 
                      <div className='checked-words-div'><span>{showTypeTitles}</span></div>  
                    </div>
                    }
                  </WeaFormItem>
                )
              })
            }
          })
          arr.push(
            <WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@w8re5i@${index}`}  needTigger={false} showGroup={true} items={items} col = {1} />
          );
        })
        return <div>{arr}</div>
    }
}
export {Condition}
